package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {
    @Select(" select * from user ")
    public List<User> findAllUser();

    @Select("select *from user where username=#{username} and password=#{password}")
    public User login(@Param("username") String username, @Param("password") String password);
    // 注册用户
    @Insert("INSERT INTO user(username, password, nickname, phone, email, is_active, created_time) " +
            "VALUES(#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{is_active}, #{created_time})")
    @Options(useGeneratedKeys = true, keyProperty = "user_id")
    public int register(User user);
    //查询邮箱号是否存在
    @Select("SELECT * FROM user WHERE email = #{email}")
    public User findUserByEmail(String email);
    @Update("update user set password=#{password} where email=#{email}")
    int updatePasswordByEmail(@Param("email") String email, @Param("password") String password);

    // 根据用户名和加密后的密码查询用户
    @Select("select * from user where username= #{username} and password =#{password}")
    public User findUser(@Param("username") String username, @Param("password") String password);

}
